#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-12-08 10:13 上午
# @Author  : yangdy
# @File    : 2020-12-08.3.1680. 连接连续二进制数字
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def concatenatedBinary(self, n: int) -> int:
        ans, p = 0, int(10**9 + 7)
        for x in range(1, n+1):
            # ll, u = 1, x
            # while u > 0:
            #     ll, u = ll * 2, u // 2
            # ans = (ans * ll + x) % p
            ll, u = 0, x
            while u > 0:
                ll, u = ll + 1, u // 2
            ans = ((ans << ll) + x) % p
        return ans


questions = [
    (1,),
    (3,),
    (12,),
    (100,),
]


work(questions, lambda q: Solution().concatenatedBinary(q[0]))

